package il.ac.bgu.cs.heuristics.graph.pddl.parser.types;

import il.ac.bgu.cs.heuristics.utils.StringUtils;

/**
 * Enumeration of logical operators
 * 
 * @author Ronen Pinko
 * 
 */
public enum LogicalOperator {

	AND("and"), OR("or"), NOT("not"), NONE("");

	private final String operatorStr;

	private LogicalOperator(String s) {
		this.operatorStr = s;
	}

	@Override
	public String toString() {
		return operatorStr;
	}

	public static LogicalOperator from(String s) {
		if (!StringUtils.containsText(s)) {
			return NONE;
		}
		LogicalOperator operator = NONE;
		for (LogicalOperator op : LogicalOperator.values()) {
			if (op.operatorStr.equalsIgnoreCase(s)) {
				operator = op;
				break;
			}
		}
		return operator;
	}

	public boolean contradicts(LogicalOperator op) {
		return op == NOT ? this != NOT : this == NOT;
	}

	public LogicalOperator inverse() {
		return this == NOT ? NONE : NOT;
	}
}
